<?php
/*
 *   This file is part of verbum.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * 	 Copyright (c) 2008 Sergio Gabriel Teves <gabriel.sgt at gmail.com>
 */

$us = new user;
$us->userid=$param['userid'];
$ret = $loader->get($us);

if ($ret) {
	failed(String::format(s("The user {0} already exists"),$us->userid));
} else {
	//$pwd = util::createPassword(MIN_PASSWORD_LEN+2);
	$_log->debug("IPW: $pwd");
	
	$us->password=$param['password'];
	$us->name=$param['name'];
	$us->mail=$param['mail'];
	$us->lang=$param['langid'];
	$us->teamid=$param['teamid'];
	$us->timezone=$param['timezone'];

	$us->groupid=GROUP_USER;		
	$us->status=INITIAL_USER_STATE;
	//$us->passcode = $pwd;
	//$us->passexpire = util::now();	

	$ret = $loader->save($us);

	$temp = new temporal;
	$temp->id=$param['auth'];
	if ($loader->get($temp)) {
		$loader->delete($temp);
		$t2 = new temporal;
		$t2->id=$temp->filler;
		$loader->delete($t2);	
	}
	
	//mailNewUserPassword($us);
	mailNewUserWelcome($us);
	mailNewUser($us);

	success('index.php?tx='.rand(1000000000,9999999999));
}

?>